#自定义过滤器,实现颜色过滤
def index_class(index):
    if index == 1:
        return "first"
    elif index ==2:
        return "second"
    elif index == 3:
        return "third"
    else:
        return ""

from flask import session,g
from functools import wraps
#封装用户的登陆数据
def user_login_data(view_func):
    @wraps(view_func)
    def wrapper(*args,**kwargs):

        # 1,获取session用户编号
        user_id = session.get("user_id")

        # 2,根据用户编号获取对象
        user = None
        if user_id:
            from info.models import User
            user = User.query.get(user_id)

        #3, 将user数据,添加到g对象
        g.user = user

        return view_func(*args,**kwargs)

    return wrapper